#include "paramdialog.h"
#include "ui_paramdialog.h"
#include "bgapackagemanager.h"
ParamDialog::ParamDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ParamDialog)
{
	
    ui->setupUi(this);
	setWindowFlags(Qt::WindowCloseButtonHint | Qt::Dialog);
	ui->checkBox_Bypass->setHidden(true);
	BgaPackageManager::INSPECT_PARAM param = BgaPackageManager::getInstance()->GetParamFromFile();
	ui->checkBox_Cap->setChecked(param.bCapDamaged);
	ui->checkBox_Ball->setChecked(param.bBallDamaged);
	ui->checkBox_Edge->setChecked(param.bChipping);
//	ui->checkBox_Bypass->setChecked(param.bBypass);
	ui->checkBox_SaveFail->setChecked(param.bOnlySaveFail);
	
	ui->checkBox_Fluff->setChecked(param.bShowNumLabel);
	ui->checkBox_Result->setChecked(param.bResultCali);
	ui->checkBox_Keep->setChecked(param.bKeepImageRatio);
	//ui->checkBox_Seperate->setChecked(param.bSeperateFolder);
	ui->spinBox->setValue(param.miniChippingArea);
	ui->spinBox_2->setValue(param.miniDamagedRatio);
	ui->spinBox_3->setValue(param.miniCircularity);
	ui->spinBox_4->setValue(param.miniAreaRatio);
	ui->spinBox_5->setValue(param.maxAreaRatio);
	//ui->spinBox_6->setValue(param.iCountForSeperateFolder);
	ui->spinBox_9->setValue(param.miniDamagedContLength);
	ui->spinBoxCrescent->setValue(param.miniCrescentArea);
	ui->spinBox_7->setValue(param.saveDays);
	PACKAGE_INFO info = StaticFunction::GetPackageInfo();

	//if (info.hdVersion != 6)
	{
		ui->verticalLayout->removeWidget(ui->groupBoxCrescent);
		ui->groupBoxCrescent->setHidden(true);
		ui->spinBoxCrescent->setHidden(true);
		ui->label_7->setHidden(true);
	}

	connect(ui->pushButton, &QPushButton::clicked, [=]() {
		BgaPackageManager::INSPECT_PARAM param;
	//	param.bBallMiss = ui->checkBox_Miss->isChecked();
		param.bCapDamaged = ui->checkBox_Cap->isChecked();
		param.bBallDamaged = ui->checkBox_Ball->isChecked();
		param.bChipping = ui->checkBox_Edge->isChecked();
	//	param.bBypass = ui->checkBox_Bypass->isChecked();
		param.bShowNumLabel = ui->checkBox_Fluff->isChecked();
		param.bResultCali = ui->checkBox_Result->isChecked();
		param.bKeepImageRatio = ui->checkBox_Keep->isChecked();
		param.bOnlySaveFail = ui->checkBox_SaveFail->isChecked();
	//	param.bSeperateFolder = ui->checkBox_Seperate->isChecked();

		param.miniDamagedRatio = ui->spinBox_2->value();
		param.miniChippingArea = ui->spinBox->value();
		param.miniCircularity = ui->spinBox_3->value();
		param.miniAreaRatio = ui->spinBox_4->value();
		param.maxAreaRatio = ui->spinBox_5->value();
		//param.iCountForSeperateFolder = ui->spinBox_6->value();
		param.miniDamagedContLength = ui->spinBox_9->value();
		param.miniCrescentArea = ui->spinBoxCrescent->value();
		param.saveDays = ui->spinBox_7->value();
		BgaPackageManager::getInstance()->SaveParamToFile(param);
		QDialog::close();
	});

	connect(ui->pushButton_2, &QPushButton::clicked, [=]() {
		QDialog::close();
	});
}

ParamDialog::~ParamDialog()
{
    delete ui;
}
